package com.adou.d16.io;

import java.io.*;

/**
 * 复制文件
 */
public class OTest3 {
    public static void main(String[] args) {
        InputStream is = null;
        OutputStream os = null;
        try {
            // 读取
            is = new FileInputStream("D:\\file\\image.jpg");

            // 写入
            os = new FileOutputStream("C:\\data\\image.jpg");

            // 创建一个字节数组
            byte[] buffer = new byte[1024];// 1kb

            // 读取多少写入多少
            int len; // 记住读取多少字节
            while((len=is.read(buffer))  != -1 ) { // 桶
                os.write(buffer, 0, len);
            }
            System.out.println("复制完成");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if(os != null) {
                    os.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                if(is !=null) {
                    is.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}
